//
//  QWViewController.m
//  QWImagePickerManager
//
//  Created by ranjingfu on 01/18/2016.
//  Copyright (c) 2016 ranjingfu. All rights reserved.
//

#import "QWViewController.h"
#import "QWPickerManger.h"
#import "MBProgressHUD.h"

@interface QWViewController ()<QWImagePickerManagerDelegate>
@property(nonatomic, strong)QWImagePickerManager *pickerManager;
@end

@implementation QWViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [ALAssetsGroupEnumerator sharedInstance];
    
    //   NSBundle  *bundle = [NSBundle allBundles];
    
    UIImage *image = [UIImage imageNamed:@"QWImagePickerController.bundle/icon_select_50.png"];
    NSLog(@"viewDidLoad:%@",image);
    
    NSString *mainBundlePath = [[NSBundle mainBundle] executablePath];
    NSString  *strBundlePath =  [mainBundlePath stringByDeletingLastPathComponent];
    strBundlePath = [strBundlePath stringByAppendingPathComponent:@"/QWImagePickerController.bundle"];
    //[[NSBundle mainBundle] executablePath] ;
    self.view.backgroundColor = [UIColor whiteColor];
    
    // NSBundle *bundle =  [NSBundle bundleWithPath:strBundlePath];
    
    UIButton  *button = [[UIButton alloc] initWithFrame:CGRectMake(40, 64, 100, 40)];
    [button setTitle:@"选择相片" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(showPhotos:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    
    
    UIButton  *buttonVideo = [[UIButton alloc] initWithFrame:CGRectMake(40, 104, 100, 40)];
    [buttonVideo setTitle:@"选择视频" forState:UIControlStateNormal];
    [buttonVideo addTarget:self action:@selector(showVideo:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:buttonVideo];
    [buttonVideo setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    
    
    UIButton  *buttonP = [[UIButton alloc] initWithFrame:CGRectMake(40, 154, 100, 40)];
    [buttonP setTitle:@"progress" forState:UIControlStateNormal];
    [buttonP addTarget:self action:@selector(showProgress:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:buttonP];
    [buttonP setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    // Do any additional setup after loading the view, typically from a nib.
}


-(void)showProgress:(id)sender
{
    MBProgressHUD  *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.labelText = @"HHhsdchsdf";
    [hud show:YES];
    [self performSelector:@selector(hideToast:) withObject:nil afterDelay:1];
    
}
-(void)hideToast:(id)sender
{
    [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
}
-(void)showVideo:(id)sender
{
    self.pickerManager = [[QWImagePickerManager alloc] initWithMaxImageCnt:3 specificUserInfo:nil delegate:self];
    [self.pickerManager presentCameraOn:self forPhotos:NO Animated:YES];
}


-(void)showPhotos:(id)sender
{
    self.pickerManager = [[QWImagePickerManager alloc] initWithMaxImageCnt:3 specificUserInfo:nil delegate:self];
    [self.pickerManager presentCameraOn:self forPhotos:YES Animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)QWImagePickerManager:(QWImagePickerManager *)picker
          didPickImageAssets:(NSArray *)selectedAssets
{
    NSLog(@"myImagePickerManager:%@ didPickImageAssets:%@",picker,selectedAssets);
}

- (void)QWImagePickerManager:(QWImagePickerManager *)picker
                didPickVideo:(NSDictionary *)infoDict
{
    NSLog(@"myImagePickerManager:%@ didPickVideo:%@",picker,infoDict);
}

@end
